package com.atstudy.set;

import java.util.Iterator;
import java.util.TreeSet;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/1/3 14:08
 * @copyright: 博为峰
 */
public class TreeSetDemo {
    public static void main(String[] args) {
//        m1();
        TreeSet treeSet = new TreeSet(new ComparatorByAge());
        treeSet.add(new Worker("zhangsan", 20));
        treeSet.add(new Worker("lisi", 30));
        treeSet.add(new Worker("wangwu", 50));
        treeSet.add(new Worker("wangwu", 50));

        Iterator iterator = treeSet.iterator();
        while (iterator.hasNext()){
            Worker worker = (Worker)iterator.next();
            System.out.println(worker.getName());
        }
    }

    private static void m1() {
        //有序
        TreeSet treeSet = new TreeSet();
        treeSet.add(new Student("zhangsan", 20));
        treeSet.add(new Student("lisi", 20));
        treeSet.add(new Student("wangwu", 50));
        treeSet.add(new Student("wangwu", 50));

        Iterator iterator = treeSet.iterator();
        while (iterator.hasNext()){
            Student student = (Student)iterator.next();
            System.out.println(student.getName());
        }
    }
}
